{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from loss import cemse\n",
    "import tensorflow as tf\n",
    "from keras import losses\n",
    "import keras.backend as K"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess = tf.InteractiveSession()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_true = tf.constant([[0.9,0,0,1,0,0,0,0,0,0], [0.9,0,0,1,0,0,0,0,0,0]])\n",
    "y_pred = tf.constant([[-0.5,0.5,-0.1,-0.8,-0.3,-0.1,0.7,0.2,-0.2,-0.2], [0.5,-0.5,0.1,0.8,0.3,0.1,-0.7,-0.2,0.2,0.2]])\n",
    "\n",
    "v = tf.slice(y_pred, [0,0], [-1,1])\n",
    "z = tf.slice(y_true, [0,0], [-1,1])\n",
    "\n",
    "p = tf.slice(y_pred, [0,1], [-1,-1])\n",
    "pi = tf.slice(y_true, [0,1], [-1,-1])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.85536313,  0.19174136], dtype=float32)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loss_value = losses.mean_squared_error(z, tf.tanh(v))\n",
    "loss_value.eval()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 3.05351686,  1.51751244], dtype=float32)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loss_actions = tf.nn.softmax_cross_entropy_with_logits(labels = pi, logits = p)\n",
    "loss_actions.eval()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "out = cemse(y_true, y_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "out2 = K.square(y_pred - y_true)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.618134"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "out.eval()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.95999992,  0.25      ,  0.01      ,  3.23999977,  0.09      ,\n",
       "         0.01      ,  0.48999998,  0.04      ,  0.04      ,  0.04      ],\n",
       "       [ 0.15999998,  0.25      ,  0.01      ,  0.04      ,  0.09      ,\n",
       "         0.01      ,  0.48999998,  0.04      ,  0.04      ,  0.04      ]], dtype=float32)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "out2.eval()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "deepreinforcement",
   "language": "python",
   "name": "deepreinforcement"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
